/**
 *碰撞检测 
 */
package utils.core
{
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.IBitmapDrawable;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	public class HitTest
	{
		private var _hitCheckObject:DisplayObject;
		private var bmd:BitmapData;
		private var matrix:Matrix = new Matrix(1,0,0,1,0,0);
		
		public function HitTest(hitCheckObject:DisplayObject)
		{
			_hitCheckObject = hitCheckObject;
			if(_hitCheckObject)
			{
				bmd = new BitmapData(1,1,true,0x0);
			}
		}
		
		/**
		 *被检测对象上某个坐标处是否为非空像素 
		 * @param _x:被检测对象坐标系中检测点的X坐标
		 * @param _y:被检测对象坐标系中检测点的Y坐标
		 * @return 
		 * 
		 */		
		public function isNotEmpty(_x:Number,_y:Number):Boolean
		{
				matrix.tx = -int(_x);
				matrix.ty = -int(_y);
				bmd.setPixel(0,0,0x0);
				bmd.draw(_hitCheckObject,matrix);
				return (bmd.getPixel(0,0)>0);
		}
		
		/**
		 * 被检测对象上鼠标处非空
		 * @return 
		 * 
		 */		
		public function isNotEmptyAtMouse():Boolean
		{
			matrix.tx = -int(_hitCheckObject.mouseX);
			matrix.ty = -int(_hitCheckObject.mouseY);
			bmd.setPixel(0,0,0x0);
			bmd.draw(_hitCheckObject,matrix);
			return (bmd.getPixel(0,0)>0);
		}
		
		/**
		 *obj的当前鼠标坐标处像素是否不为空 
		 * @param obj
		 * @return 
		 * 
		 */		
		public static function notEmptyAt(obj:DisplayObject):Boolean
		{
			var matrix:Matrix = new Matrix(1,0,0,1,0,0);
			var bmd:BitmapData = new BitmapData(1,1,true,0x0);
			
			matrix.tx = -int(obj.mouseX);
			matrix.ty = -int(obj.mouseY);
			bmd.setPixel(0,0,0x0);
			bmd.draw(obj,matrix);
			return (bmd.getPixel(0,0)>0);
		}
	}
}